﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BOSS.Domain.Security;
using BOSS.Domain;

namespace BOSS.Domain.Security
{
    /// <summary>
    /// 登录信息
    /// </summary>
    [Serializable]
    public class LoginInfo : Entity<int>
    {
        /// <summary>
        /// 获取 / 设置 登录标识
        /// </summary>
        public virtual Guid Guid { get; set; }

        /// <summary>
        /// 获取 / 设置 帐号信息
        /// </summary>
        public virtual Account Account { get; set; }

        /// <summary>
        /// 获取 / 设置 登录时间
        /// </summary>
        public virtual DateTime LoginTime { get; set; }

        /// <summary>
        /// 获取 / 设置 登录过期时间
        /// </summary>
        public virtual DateTime ExpireTime { get; set; }

        /// <summary>
        /// 获取 / 设置 刷新时间
        /// </summary>
        public virtual DateTime RefreshTime { get; set; }

        /// <summary>
        /// 获取 / 设置 IP 地址
        /// </summary>
        public virtual string IpAddress { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public LoginInfo() : this(Guid.NewGuid(), null, "127.0.0.1")
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="account"></param>
        /// <param name="ipAddress"></param>
        public LoginInfo(Guid guid, Account account, string ipAddress)
        {
            this.Guid = guid;
            this.Account = account;
            this.IpAddress = ipAddress;
            this.LoginTime = DateTime.Now;
            this.RefreshTime = this.LoginTime;
            this.ExpireTime = this.LoginTime.AddDays(1); // 50 年不过期，除非关闭浏览器
        }
    }
}
